﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ClearSweet : MonoBehaviour
{
    public AnimationClip clearAni;
    private bool isclear;
    public AudioClip destroyAudio;
    public bool Isclear { get => isclear;  }
    protected Gamesweet sweet;
    /// <summary>
    /// 清除协程开启
    /// </summary>
    private void Awake()
    {
      //  sweet=GetComponent<Gamesweet>(
    }
    public virtual void Clear()
    {
        isclear = true;
        StartCoroutine(ClearSweets());
    }
   private IEnumerator ClearSweets()
    {
        Animator ani = GetComponent<Animator>();
        if(ani!=null)
        {
            ani.Play(clearAni.name);
            GameManager.Instance.Score++;
            AudioSource.PlayClipAtPoint(destroyAudio,transform.position);
            yield return new WaitForSeconds(clearAni.length);
            Destroy(gameObject);
        }
    }
}
